// import * as tf from "@tensorflow/tfjs";
let tf = require("@tensorflow/tfjs");
/*
//默认向量
let a = tf.tensor2d([
  [1, 2],
  [3, 4, 5],
]);

console.log(a.shape);
a.print();

// 声明向量 [有几组数据，每组数据有几个元素]
let shape = [4, 1];
let b = tf.tensor([1, 2, 3, 4], shape);
b.print();

let c = b.reshape([1, 4]); //修改向量
c.print();

//从张量中取值
b.array().then((item) => {
  console.log(item, "----a");
});
b.data().then((item) => {
  console.log(item, "----a----b");
});

*/

//张量的计算
// let e = b.square();
// let f = b.square().square();
// e.print();
// f.print();

// console.log(tf.getBackend(), "环境后端");

const tensor_s = tf.tensor([2, 2]).shape;
console.log(tensor_s, "de");

//张量计算  add加 sub减 mul乘 div除 square平方  pow幂次方
let h = tf.tensor([1, 2, 3, 4], [1, 4]);
let i = tf.tensor([1, 2, 3, 4], [1, 4]);
i.print();

let j = tf.add(h, i);
j.print();

let k = tf.sub(h, i);
k.print();

let l = tf.mul(h, i);
l.print();
let m = tf.mul(h, tf.tensor([2], [1, 1]));
m.print();

let n = tf.div(h, i);
n.print();

let o = tf.square(h);
o.print();

let p = tf.pow(h, 3);
p.print();

//定义方程
// y=10x^2+6x+3
function fn(x) {
  return tf.tidy(() => {
    let a = x.square().mul(10);
    let b = x.mul(6);

    return a.add(b).add(3);
  });
}
fn(tf.scalar(2)).print(); //方程结果

let q = tf.tensor2d([1, 2, 3, 4, 5, 6], [1, 6]);
q.print();
